package com.ytzl.demo.service.impl;

import com.ytzl.demo.service.HotCityHotelService;
import com.ytzl.vo.ItripHotCityHoteVo;
import com.ytzl.vo.SearchHotCityVO;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Service
public class HotCityHotelServiceImpl implements HotCityHotelService {
    @Resource
    private SolrClient solrClient;
    @Override
    public List<ItripHotCityHoteVo> queryHotelCityList(SearchHotCityVO searchHotCityVO) throws IOException, SolrServerException {
        System.out.println("Service数据"+searchHotCityVO.cityId);
        System.out.println("Service数据"+searchHotCityVO.count);

        //构造solr的查询条件
        SolrQuery query = new SolrQuery();

        query.setQuery("*:*");
        query.setFilterQueries("cityId:"+searchHotCityVO.cityId);
        //设置分页
        query.setStart(0);
        query.setRows(searchHotCityVO.count);
        //设置排序
        query.setSort("id",SolrQuery.ORDER.desc);

        //执行查询，获取查询结果
        QueryResponse response = solrClient.query(query);
        //将从solr查询到的数据转换为java对象
        return response.getBeans(ItripHotCityHoteVo.class);
    }
}
